<link type="text/css" rel="stylesheet" href="<?php echo $this->assetDir ?>css/kdt/user.css" />
<link type="text/css"  rel="stylesheet" href="<?php echo $this->assetDir ?>css/kdt/schedules.css">
<div class="row-fluid">
    <div class="box span12">
        <?php
        Yii::app()->clientScript->registerScript('search2', "
            $('.service-search-form form').submit(function(){
                $('#service-grid').yiiGridView('update', {
                    data: $(this).serialize()
                });
               
                return false;
            });
    ");
        ?>
        <div class="box-header" data-original-title>
            <h2>
                <i class="icon-user"></i><span class="break"></span>
                <span class="stitle"><?php echo Yii::app()->request->getQuery('type', 0) == Service::TYPE_ROOM ? 'Class' : 'Service' ?></span>
            </h2>
        </div>

        <div class="box-content">
            <ul class="nav tab-menu nav-tabs">
                <li id="activeService" <?php echo Yii::app()->request->getQuery('type', 0) == Service::TYPE_SERVICE ? 'class="active"' : '' ?>>
                    <a href="#">
                        Service
                    </a>
                </li>
                <li id="activeClass" <?php echo Yii::app()->request->getQuery('type', 0) == Service::TYPE_ROOM ? 'class="active"' : '' ?>>
                    <a href="#">
                        Class
                    </a>
                </li>
            </ul>
            <?php
            $script          = "
                var link ='#'
                $('#activeService').live('click',function(){
                    $('.stitle').html('Service');
                    $('#activeService').addClass('active');
                    $('#activeClass').removeClass('active');
                    $('#s_name').val('');
                    $('#type').val(0);
                    link='" . Yii::app()->createUrl('service/create', array('t' => Service::TYPE_SERVICE)) . "';
                    $('.service-search-btn').trigger('click');
                    $('.s_add_link').attr('href',link)
                })

                 $('#activeClass').live('click',function(){
                    $('.stitle').html('Class');
                    $('#activeService').removeClass('active');
                    $('#activeClass').addClass('active');
                    $('#s_name').val('');
                    $('#type').val(1);
                    link='" . Yii::app()->createUrl('service/create', array('t' => Service::TYPE_ROOM)) . "';
                    $('.s_add_link').attr('href',link)
                    $('.service-search-btn').trigger('click');
                })
            ";
            cs()->registerScript("#acbdefe", $script);
            ?>

            <div class="row-fluid">
                <div class="pull-left search-form service-search-form">
                    <!--            Search content-->
                    <?php
                    $form            = $this->beginWidget('CActiveForm', array(
                        'action' => Yii::app()->createUrl($this->route),
                        'method' => 'get',
                    ));
                    ?>
                    <?php echo CHtml::hiddenField('type'); ?>
                    <?php // echo $form->textField($model, 's_name', array('placeHolder' => 'Service name')) ?>
                    <?php
//                        echo $form->dropDownList($model, 'author_id', Merchant::get_all_merchant(FALSE, TRUE), array(
//                            'data-rel' => "chosen",
//                        ));
                    ?>
                    <?php //echo CHtml::submitButton('search',array('class'=>'btn btn-success'));  ?>
                    <input id="search" class="btn btn-success service-search-btn hide" type="submit" value="search">
                    <?php $this->endWidget(); ?>
                    <!--            End Search content-->
                </div>

                <div class="pull-right">
                    <p>
                        <a href="<?php
                        echo Yii::app()->createUrl('service/create', array(
                            't' => Yii::app()->request->getQuery('type', 0)
                        ));
                        ?>" class="btn btn-primary s_add_link" >
                            <i class="icon-plus"></i> Add <span class="stitle"><?php echo Yii::app()->request->getQuery('type', 0) == Service::TYPE_ROOM ? 'Class' : 'Service' ?></span>
                        </a>
                    </p>
                </div>
            </div>
            <?php
            $categories_data = array('' => 'Select Category') + CHtml::listData(Category::GetAllCategoryByRole(), 'id', 'name_cat', 'group');
            $this->widget('application.widgets.MyBaseListView', array(
                'id'              => 'service-grid',
                'filter'          => true,
                'afterAjaxUpdate' => 'function(id,data){$("[data-rel=\'chosen\'],[rel=\'chosen\']").chosen();}',
                'dataProvider'    => $model->search(),
                'columns'         => array(
                    array(
                        'header'      => 'Image',
                        'type'        => 'raw',
                        'value'       => 'CHtml::image($data->get_avatar_by_size(80,80),"",array("class"=>"thumb_on_list"))',
                        'htmlOptions' => array(
                            'width' => '10%',
                            'class' => 'text-center',
                        ),
                    ),
                    array(
                        'header' => 'Name',
                        'name'   => 's_name',
                        'type'   => 'raw',
                        'value'  => 'CHtml::link($data->s_name,$data->editUrl,array("target"=>"blank"))',
                        'filter' => CHtml::textField('Service[s_name]', $model->s_name, array('placeHolder' => 'Search name')),
                    ),
                    array(
                        'header'      => 'Category',
                        'name'        => 'category_id',
                        'type'        => 'raw',
                        'value'       => $this->isAdmin ? 'CHtml::link(@$data->category->name,@$data->category->editUrl,array("target"=>"blank"))' : '@$data->category->name',
                        'filter'      => CHtml::dropDownList("Service[category_id]", $model->category_id, $categories_data, array(
                            "data-rel" => "chosen"
                        )),
                        'htmlOptions' => array(
                        ),
                    ),
                    array(
                        'header'      => 'Merchant',
                        'name'        => 'author_id',
                        'type'        => 'raw',
                        'value'       => $this->isAdmin ? 'CHtml::link(@$data->user->name,@$data->user->editUrl,array("target"=>"blank"))' : '@$data->user->name',
                        'filter'      => $this->isAdmin ? CHtml::dropDownList("Service[author_id]", $model->author_id, Merchant::get_all_merchant(FALSE, TRUE), array("data-rel" => "chosen")) : false,
                        'htmlOptions' => array(
                        ),
                    ),
                    array(
                        'header'      => 'Duration',
                        #'name'=>'duration',
                        'type'        => 'raw',
                        'value'       => '$data->durationTime',
                        'filter'      => false,
                        'htmlOptions' => array(
                        //'width'=>'%'
                        ),
                    ),
                    array(
                        'header'      => 'Price',
                        'type'        => 'raw',
                        'value'       => '"$".$data->priceFormat',
                        'filter'      => false,
                        'htmlOptions' => array(
                        //'width'=>'%'
                        ),
                    ),
                    array(
                        'header'      => 'Points',
                        'type'        => 'raw',
                        'value'       => '$data->user!=null? ($data->user->service!=null? $data->price * $data->user->service->money_to_points:0):0',
                        'filter'      => false,
                        'htmlOptions' => array(
                        //'width'=>'%'
                        ),
                    ),
                    //Book Online
                    array(
                        'header'      => 'Book Online',
                        'type'        => 'raw',
                        'value'       => '$data->book_online ? "<i class=\"icon-ok\"></i>":0',
                        'filter'      => false,
                        'htmlOptions' => array(
                        //'width'=>'%'
                        ),
                    ),
                    array(
                        'class'       => 'CButtonColumn',
                        'template'    => '{update}',
                        'htmlOptions' => array(
                            'width' => '10%'
                        ),
                        'buttons'     => array(
                            'update' => array(
                                'url'      => 'url("service/update",array("id"=>$data->sid))',
                                'imageUrl' => false,
                                'label'    => '<i class="icon-edit"></i>',
                                'options'  => array(
                                    'class'  => 'btn btn-info',
                                    'target' => '_blank',
                                    'title'  => 'Update'
                                ),
                            ),
                        ),
                    ),
                ),
            ));
            ?>
            <!--    </div>-->
        </div>
    </div>
</div>
<?php
$css             = ".filters input {margin-bottom: 0px ;padding: 0px;max-width: auto;}"
        . ".chzn-container{width: 190px!important}.chzn-drop{top: 27px!important; width: 188px!important}.chzn-search input{width: 153px!important}"
        . ".box-content{min-height:400px}";
cs()->registerCss("#" . uniqid(), $css);
?>